package ent

import (
	"ai-curd/oo"
)

func (entArticle *Article) Mapper() oo.Article {
	if entArticle == nil {
		return nil
	}

	ooArticle := oo.NewArticle(entArticle.Category)
	ooArticle.SetID(entArticle.ID)
	ooArticle.SetCategory(entArticle.Category)
	ooArticle.SetTitle(entArticle.Title)
	ooArticle.SetContent(entArticle.Content)
	return ooArticle
}

func (entArticles Articles) Mapper() oo.Articles {
	size := len(entArticles)
	ooArticles := make(oo.Articles, size)
	for i := 0; i < size; i++ {
		ooArticles[i] = entArticles[i].Mapper()
	}
	return ooArticles
}
